import { AutoCenter } from 'antd-mobile';
import { STATUS, TIPS, usePullToRefresh } from './hooks';

interface lProps {
  children:React.ReactNode;
  onRefresh:()=>void;
}

/**
 * 下拉刷新组件
 * 仅供学习使用(没有下拉动画及性能优化等)
 * @param param0
 * @returns
 */
const PullToRefresh = ({
  children,
  onRefresh,
}: lProps) => {
  const { status, containerRef } = usePullToRefresh(onRefresh);
  return (
    <div ref={containerRef}>
      {/* children: 列表页的数据 */}
      {status !== STATUS.FINISH && <AutoCenter>{ TIPS.status }</AutoCenter>}
      {children}
    </div>
  );
};

export default PullToRefresh;
